<template>
  <div class="nav-header">
    <i
      class="back"
      :class="isBack ? 'el-icon-back' : 'el-icon-right'"
      @click="handleBackClick"
    ></i>
    <div class="content">
      <ZZYbreadcrumb :breadcrumbitem="breadcrumbitem" />
      <userInofo />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import userInofo from './user-info.vue'
import ZZYbreadcrumb from '@/base-ui/nav-breadcrumb'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  components: {
    userInofo,
    ZZYbreadcrumb
  },
  emits: ['backChange'],
  setup(props, { emit }) {
    const isBack = ref(false)
    const handleBackClick = () => {
      isBack.value = !isBack.value
      emit('backChange', isBack.value)
    }

    //面包屑 usemenus: any[], path: string
    const store = useStore()
    const breadcrumbitem = computed(() => {
      const usemenus = store.state.loginModule.UserMenus
      const route = useRoute()
      const path = route.path
      return pathMapBreadcrumbs(usemenus, path)
    })

    return {
      isBack,
      breadcrumbitem,
      handleBackClick
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;

  .back {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
